package com.xilihui.xlh.business.dialogs;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.business.adapters.BillAdapter;
import com.xilihui.xlh.business.entities.AccountEntity;
import com.xilihui.xlh.core.util.ScreenUtil;

import java.util.ArrayList;


/**
 * Created by Administrator on 2018/7/9.
 */

public class BillScreeningDialog implements View.OnClickListener {
    
    private Activity activity;
    private Dialog dialog;
    private GridView gridView;
    private TextView textView;
    
    BillAdapter billAdapter;
    
    ArrayList<AccountEntity.StaBean> data = new ArrayList<>();
    
    public BillScreeningDialog(Activity activity,ArrayList<AccountEntity.StaBean> data){
        this.activity = activity;
        this.data.addAll(data);
        dialog = new Dialog(this.activity, R.style.Dialog);
        initView();
        
    }
    
    public void initView(){

        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_bill_screening,null);
        gridView = (GridView) view.findViewById(R.id.gridview);
        textView = (TextView)view.findViewById(R.id.tv_cancle);
        textView.setOnClickListener(this);
        
        billAdapter = new BillAdapter(activity,data);
        gridView.setAdapter(billAdapter);
        dialog.setContentView(view);
        setDialogWidth();
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);

    }

    public void setDialogWidth(){
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = ScreenUtil.getScreenWidth(activity);
        dialog.getWindow().setAttributes(lp);
    }
    
    public void show(){
        dialog.show();
    }
    
    public void dismiss(){
        dialog.dismiss();
    }


    @Override
    public void onClick(View view) {
        dialog.dismiss();
    }
}
